package com.javelingroup.navigate.breadcrumb;

import java.util.ArrayList;
import java.util.List;

import com.javelingroup.navigate.model.Crumbs;

public class NavigationBreadCrumbService {
	
	public List<Crumbs> createBreadCrumbs(String tempBreadCrumb) {
		
		List<Crumbs> crumbs = new ArrayList<Crumbs>();
		
		String[] seperatedBreadCrumb = tempBreadCrumb.split(",");
		
		//In case seperatedBreadCrumb==1 it means that we are have nothing selected. We need to add the home
		if(seperatedBreadCrumb.length==1){
			crumbs.add(new Crumbs("Media","Media"));
		}
		
		for(int i = 1; i<seperatedBreadCrumb.length; i++){
			
			String tmpBreadCrumbLocation = "";
			String tmpBreadCrumbName = "";
			
			for(int n = 0; n<i; n++){

				String seperator="";
				
				if(n>0){
					seperator=",";
				}else{
					seperator="";
				}
				
				tmpBreadCrumbLocation = tmpBreadCrumbLocation + seperator + seperatedBreadCrumb[n];
				
				if(n==i-1){
					tmpBreadCrumbName = seperatedBreadCrumb[n];
				}
			}
			
			crumbs.add(new Crumbs(tmpBreadCrumbName,tmpBreadCrumbLocation));
			
		}
		
		return crumbs;
	}

}
